package com.example.jdk8.time;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Period;
import java.time.temporal.TemporalAdjusters;

public class java8Test8 {
    public static void main(String[] args) {

//        日期API工具：我们早些时候提到过，大多数日期/时间API类都实现了一系列工具方法，如：加/减天数、周数、月份数，等等。
//        还有其他的工具方法能够使用TemporalAdjuster调整日期，并计算两个日期间的周期

        LocalDate today = LocalDate.now();

        //Get the Year, check if it's leap year
        System.out.println("Year " + today.getYear() + " is Leap Year? " + today.isLeapYear());

        //Compare two LocalDate for before and after
        System.out.println("Today is before 01/01/2015? " + today.isBefore(LocalDate.of(2015, 1, 1)));

        //Create LocalDateTime from LocalDate
        System.out.println("Current Time=" + today.atTime(LocalTime.now()));

        //plus and minus operations
        System.out.println("10 days after today will be " + today.plusDays(10));
        System.out.println("3 weeks after today will be " + today.plusWeeks(3));
        System.out.println("20 months after today will be " + today.plusMonths(20));

        System.out.println("10 days before today will be " + today.minusDays(10));
        System.out.println("3 weeks before today will be " + today.minusWeeks(3));
        System.out.println("20 months before today will be " + today.minusMonths(20));

        //Temporal adjusters for adjusting the dates
        System.out.println("First date of this month= " + today.with(TemporalAdjusters.firstDayOfMonth()));
        LocalDate lastDayOfYear = today.with(TemporalAdjusters.lastDayOfYear());
        System.out.println("Last date of this year= " + lastDayOfYear);

        Period period = today.until(lastDayOfYear);
        System.out.println("Period Format= " + period);
        System.out.println("Months remaining in the year= " + period.getMonths());

//        Year 2014 is Leap Year? false
//        Today is before 01/01/2015? true
//        Current Time=2014-04-28T16:23:53.154
//        10 days after today will be 2014-05-08
//        3 weeks after today will be 2014-05-19
//        20 months after today will be 2015-12-28
//        10 days before today will be 2014-04-18
//        3 weeks before today will be 2014-04-07
//        20 months before today will be 2012-08-28
//        First date of this month= 2014-04-01
//        Last date of this year= 2014-12-31
//        Period Format= P8M3D
//        Months remaining in the year= 8

    }
}
